<?php

/**
 * DeliveryRule filter form base class.
 *
 * @package    tsantek-shop
 * @subpackage filter
 * @author     Tomislav Šantek
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseDeliveryRuleFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'shop_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Shop'), 'add_empty' => true)),
      'product_id'   => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Product'), 'add_empty' => true)),
      'region'       => new sfWidgetFormChoice(array('choices' => array('' => '', 'city' => 'city', 'county' => 'county', 'zip' => 'zip', 'country' => 'country'))),
      'region_id'    => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'is_free'      => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'override_all' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'amount'       => new sfWidgetFormFilterInput(array('with_empty' => false)),
    ));

    $this->setValidators(array(
      'shop_id'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Shop'), 'column' => 'id')),
      'product_id'   => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Product'), 'column' => 'id')),
      'region'       => new sfValidatorChoice(array('required' => false, 'choices' => array('city' => 'city', 'county' => 'county', 'zip' => 'zip', 'country' => 'country'))),
      'region_id'    => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'is_free'      => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'override_all' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'amount'       => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
    ));

    $this->widgetSchema->setNameFormat('delivery_rule_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'DeliveryRule';
  }

  public function getFields()
  {
    return array(
      'id'           => 'Number',
      'shop_id'      => 'ForeignKey',
      'product_id'   => 'ForeignKey',
      'region'       => 'Enum',
      'region_id'    => 'Number',
      'is_free'      => 'Boolean',
      'override_all' => 'Boolean',
      'amount'       => 'Number',
    );
  }
}
